In a Java Virtual Machine™ and other similar run-time environments, managing available memory is important to maintain performance and reliability. Typically, memory is allocated for an executing program from a pool of memory called a heap. When the executing program creates a new object, available memory in the heap is allocated for the object. Since the amount of memory available in the heap is limited, objects that are no longer used by the program need to be reclaimed, freeing up memory space.
Garbage collection is a form of memory management commonly used to gather up and recover unused and/or dead memory space in a heap. During execution of a program, a garbage collector attempts to identify memory allocated to objects that are unreachable or no longer in use by the executing program. A garbage collector deallocates any memory allocated to objects that are no longer reachable, freeing the memory space for future use.